リスト内包表記 (hs)
https://kowainik.github.io/posts/arrows-zoo#comprehension
Listモナドに対する操作を数学の集合の定義っぽくリストを書ける
code:hs
-- 式 | リストの要素値 <- リスト, 条件
[ n | n <- 1..10, n mod 2 /= 0 ] -- 1,3,5,7,9
code:hs
[x | x <- 1..10, even x] -- 2,4,6,8,10
タプルリストも作れる
code:hs
[ (x, y) | x <- 1,2,3, y <- 11,12 ]
-- (1,11),(1,12),(2,11),(2,12),(3,11),(3,12)
リスト内包表記はdoの糖衣構文 ref
以下のやつの糖衣構文
code:hs
-- リスト >>= \リストの要素値 -> if 条件 then 式 else []
ns >>= \n -> if n mod p /= 0 then n
code:hs
do n <- ns
if n mod p /= 0 then n else []
https://sites.google.com/site/kiyohiko90091e/programming/haskell/gen-lists
https://blog.eiel.info/blog/2014/11/02/internal-definitia-great-study/
https://gyazo.com/383194c4f185b585b7c6c917c4e42376
https://gyazo.com/b81059dae8b50d07283dfb28e648791a
モナドというかdo式